<template>
  <div class="app-container">
    <!-- 历史记录界面 -->
    <header class="app-header">
      <el-form inline label-width="140px">
        <el-form-item label="品牌：" prop="brand">
          <el-input
            v-model.trim="query.brand"
            clearable
            @clear="selected"
          />
        </el-form-item>
        <el-form-item label="名称：" prop="materialName">
          <el-input
            v-model.trim="query.materialName"
            clearable
            @clear="selected"
          />
        </el-form-item>
        <el-form-item label="内部单号：" prop="innerCode">
          <el-input
            v-model.trim="query.innerCode"
            clearable
            @clear="selected"
          />
        </el-form-item>
        <el-form-item label="记录编号：" prop="recordCode">
          <el-input
            v-model.trim="query.recordCode"
            clearable
            @clear="selected"
          />
        </el-form-item>
        <el-form-item label="入库/出库批次号：" prop="batchCode">
          <el-input
            v-model.trim="query.batchCode"
            clearable
            @clear="selected"
          />
        </el-form-item>
        <!-- <el-form-item label="请购单号：" prop="orderCode">
					<el-input
						v-model.trim.number="query.orderCode"
						clearable
						@clear="selected"
					/>
				</el-form-item> -->
        <el-form-item label="规格：" prop="specifications">
          <el-input
            v-model.trim="query.specifications"
            clearable
            @clear="selected"
          />
        </el-form-item>
        <el-form-item label="图号：" prop="chartNo">
          <el-input
            v-model.trim="query.chartNo"
            clearable
            @clear="selected"
          />
        </el-form-item>
        <el-form-item label="操作类型：" prop="operateType">
          <el-select
            v-model="query.operateType"
            clearable
            @clear="selected"
          >
            <el-option
              v-for="(label, key) in operateTypeMap"
              :key="key"
              :label="label"
              :value="key"
            >{{ label }}</el-option
            >
          </el-select>
        </el-form-item>
        <el-form-item label="物料类型：" prop="materialType">
          <el-select
            v-model="query.materialType"
            clearable
            @clear="selected"
          >
            <el-option
              v-for="(label, key) in materialTypeMap"
              :key="key"
              :label="label"
              :value="key"
            >{{ label }}</el-option
            >
          </el-select>
        </el-form-item>
        <el-form-item label="采购类型：" prop="purchaseType">
          <el-select
            v-model="query.purchaseType"
            clearable
            @clear="selected"
          >
            <el-option
              v-for="(label, key) in purchaseTypeMap"
              :key="key"
              :label="label"
              :value="key"
            >{{ label }}</el-option
            >
          </el-select>
        </el-form-item>
      </el-form>

      <div class="establish">
        <el-button
          type="primary"
          size="small"
          @click="selected"
        >查询</el-button
        >
        <el-button plain size="small" @click="reset">重置</el-button>
      </div>
    </header>

    <el-table
      v-loading="loading"
      :data="list"
      :header-row-style="{
        'background-color': '#E6E6E6',
        'font-weight': 'bold',
        color: '#333',
      }"
      :tree-props="{
        children: 'children',
        hasChildren: 'hasChildren',
      }"
      border
      style="width: 100%; margin-bottom: 20px"
      row-key="id"
    >

      <el-table-column
        show-overflow-tooltip
        align="center"
        width="150"
        prop="innerCode"
        label="内部单号"
      />
      <el-table-column
        show-overflow-tooltip
        align="center"
        prop="chartNo"
        width="150"
        label="图号"
      />
      <el-table-column
        show-overflow-tooltip
        align="center"
        prop="materialName"
        label="物料名称"
        width="200"
      />
      <el-table-column
        show-overflow-tooltip
        align="center"
        prop="materialType"
        label="物料类型"
      >
        <template slot-scope="scope">
          {{ materialTypeMap[scope.row.materialType] || "--" }}
        </template>
      </el-table-column>

      <el-table-column
        show-overflow-tooltip
        align="center"
        prop="materialType"
        label="采购类型"
      >
        <template slot-scope="scope">
          {{
            scope.row.materialType == 2
              ? purchaseTypeMap[scope.row.purchaseType]
              : "--"
          }}
        </template>
      </el-table-column>

      <el-table-column
        show-overflow-tooltip
        align="center"
        prop="batchCode"
        width="150"
        label="入库/出库批次号"
      />
      <!-- <el-table-column
				show-overflow-tooltip
				align="center"
				prop="deliveryUnit"
				width="150"
				label="出库送货单位"
			/> -->
      <el-table-column
        show-overflow-tooltip
        align="center"
        prop="brand"
        label="品牌"
      />
      <el-table-column
        show-overflow-tooltip
        align="center"
        prop="specifications"
        label="规格"
      />
      <el-table-column
        show-overflow-tooltip
        align="center"
        prop="operateType"
        label="操作类型"
      >
        <template slot-scope="scope">
          {{ operateTypeMap[Number(scope.row.operateType)] }}
        </template>
      </el-table-column>
      <el-table-column
        show-overflow-tooltip
        align="center"
        prop="applyAmount"
        label="申请数量"
      />
      <el-table-column
        show-overflow-tooltip
        align="center"
        prop="realAmount"
        label="库存数量"
      />
      <el-table-column
        show-overflow-tooltip
        align="center"
        prop="pdfUrl"
        label="送货单"
      >
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.pdfUrl"
            type="text"
          ><a
            :href="scope.row.pdfUrl"
            target="blank"
          >下载</a
          ></el-button
          >
        </template>
      </el-table-column>
      <el-table-column
        show-overflow-tooltip
        align="center"
        prop="address"
        width="200"
        label="地址"
      />
      <el-table-column
        show-overflow-tooltip
        align="center"
        prop="phone"
        label="手机号"
        width="110"
      />
      <el-table-column
        show-overflow-tooltip
        align="center"
        prop="clientName"
        width="110"
        label="客户"
      />
      <el-table-column
        show-overflow-tooltip
        align="center"
        prop="deliveryDate"
        label="出库收货日期"
        width="150"
      />
      <el-table-column
        show-overflow-tooltip
        align="center"
        prop="unit"
        label="单位"
      />
      <el-table-column
        show-overflow-tooltip
        align="center"
        prop="price"
        label="价格"
      />
      <el-table-column
        show-overflow-tooltip
        align="center"
        prop="totalPrice"
        label="总价"
      />
      <!-- <el-table-column
				show-overflow-tooltip
				align="center"
				prop="comments"
				label="备注"
			/> -->
    </el-table>

    <el-pagination
      :current-page="query.page"
      :total="total"
      :page-size="query.limit"
      style="padding: 30px 0; text-align: end"
      layout="total, prev, pager, next,jumper"
      @current-change="fetchData"
    />
  </div>
</template>

<script>
import user from '../../api/acl/user.js'
import {
  materialTypeMap,
  purchaseTypeMap,
  operateTypeMap
} from '../../utils/const'
export default {
  name: 'History',

  data() {
    return {
      query: {
        brand: '',
        innerCode: '',
        materialName: '',
        specifications: '',
        purchaseType: '',
        materialType: '',
        operateType: '',
        chartNo: '',
        recordCode: '',
        batchCode: '',
        page: 1,
        limit: 10
      },
      list: [],
      total: 1,
      loading: false,
      materialTypeMap,
      purchaseTypeMap,
      operateTypeMap
    }
  },

  created() {
    this.getList()
  },

  methods: {
    reset() {
      this.query = {
        brand: '',
        materialName: '',
        specifications: '',
        purchaseType: '',
        material_type: '',
        chartNo: '',
        page: 1,
        limit: 10
      }
      this.getList()
    },
    selected() {
      this.getList()
    },
    fetchData(val) {
      this.query.page = val
      this.getList()
    },
    getList() {
      const query = Object.assign({}, this.query, {
        operateType: this.query.operateType ? this.query.operateType != 0 : ''
      })
      this.loading = true
      user.listPlateStorageRecord(query).then((response) => {
        this.total = response.total
        this.loading = false
        this.list = response.list
      })
    }
  }
}
</script>

<style>
.establish {
	text-align: right;
}
</style>
